package com.xl.domain.pojo;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.*;
import com.xl.annotation.Excel;
import com.xl.annotation.ExcelPropertyCheck;
import com.xl.constants.ExcelPropertyTypeConstants;
import lombok.Data;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/***
 * 注解解释
 *  下载模板的时候是ExcelProperty注解在起作用，拿到了表头
 *
 *  @ExcelIgnore 导出数据时候忽略这个字段
 *  @Excel(name = "设备Id" ,sort = 1)
 *          sort 导出到excel中，位于excel的第几列，从1开始
 *          name 导出时候excel中的列名
 *          readConverterExp = "1=PCF,2=DNS" 导出时遇到1会转为PCF 2 会转为DNS
 *
 */
@HeadRowHeight(30)
@HeadStyle(horizontalAlignment = HorizontalAlignment.CENTER, verticalAlignment = VerticalAlignment.CENTER)
@HeadFontStyle(fontName = "微软雅黑", fontHeightInPoints = 11, bold = false)
@ColumnWidth(20)
@ContentRowHeight(25)
@ContentStyle(horizontalAlignment = HorizontalAlignment.CENTER, verticalAlignment = VerticalAlignment.CENTER, dataFormat = 49)
@ContentFontStyle(fontName = "微软雅黑", fontHeightInPoints = 11)
@Data
public class Device implements Serializable {

    /***
     * 忽略字段
     */
    @ExcelIgnore
    private String ignore;
    /**
     *
     */
    @Excel(name = "设备ID", sort = 1)
    @ExcelProperty(value = "设备ID", index = 0)
    private Long id;
    /**
     * 设备类型1=PCF,2=DNS,3=MC,4=MDS,5=5G-IN,6=MSC,7=FAS,8=UPF
     */
    @Excel(name = "设备类型", sort = 2, readConverterExp = "1=PCF,2=DNS,3=MC,4=MDS,5=5G-IN,6=MSC,7=FAS,8=UPF")
    @ExcelProperty(value = "设备类型", index = 1)
    private Integer deviceType;
    /**
     * 设备编号
     */
    @Excel(name = "设备编号", sort = 3)
    @ExcelProperty(value = "设备编号", index = 2)
    @ExcelPropertyCheck(checkBlank = true)
    private String deviceCode;
    /**
     * 设备名称
     */
    @Excel(name = "设备名称", sort = 4)
    @ExcelProperty(value = "设备名称", index = 3)
    @ExcelPropertyCheck(checkBlank = true)
    private String deviceName;
    /**
     * 主备 1-主 0-备，如果解析的时候excel传过来的是一个String，我这里是Integer，这个时候就会给默认值是0。
     */
    @Excel(name = "主备类型", sort = 5, readConverterExp = "1=主,0=备")
    @ExcelProperty(value = "主备类型", index = 4)
    @ExcelPropertyCheck(checkBlank = true)
    private Integer masterAndSlave;
    /**
     * 域名
     */
    @Excel(name = "域名", sort = 6)
    @ExcelProperty(value = "域名", index = 5)
    @ExcelPropertyCheck(checkBlank = true)
    private String domainName;
    /**
     * 设备IP地址
     */
    @Excel(name = "设备IP", sort = 7)
    @ExcelProperty(value = "设备IP", index = 6)
    @ExcelPropertyCheck(checkBlank = true,propertyName = "设备IP",checkRegex = ExcelPropertyTypeConstants.IP_VALUE)
    private String ipAddress;


    public static List<Device> getDeviceList() {
        ArrayList<Device> list = new ArrayList<>();
        Device device1 = new Device();
        device1.setId(1l);
        device1.setDeviceCode("001");
        device1.setDeviceName("设备1");
        device1.setDeviceType(1);
        device1.setDomainName("www.hy.cn");
        device1.setIpAddress("0.0.0.0");
        device1.setMasterAndSlave(1);
        Device device2 = new Device();
        device2.setId(2l);
        device2.setDeviceCode("002");
        device2.setDeviceName("设备2");
        device2.setDeviceType(1);
        device2.setDomainName("www.hy.cn");
        device2.setIpAddress("0.0.0.0");
        device2.setMasterAndSlave(1);
        Device device3 = new Device();
        device3.setId(3l);
        device3.setDeviceCode("003");
        device3.setDeviceName("设备3");
        device3.setDeviceType(2);
        device3.setDomainName("www.hy2323.cn");
        device3.setIpAddress("1.2.3.4");
        device3.setMasterAndSlave(0);

        list.add(device1);
        list.add(device2);
        list.add(device3);
        return list;
    }

}
